package com.chainyoung.component_tmperson.ui.mvp.presenter;

import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.entity.PreRepayment;
import com.chainyoung.component_tmperson.entity.WalletDebit;
import com.chainyoung.component_tmperson.ui.mvp.contract.ConfirmRepayContract;
import com.chainyoung.component_tmperson.ui.mvp.contract.WalletDebitContract;

import java.util.List;
import java.util.TreeMap;

import javax.inject.Inject;

public class ConfirmRepayPresenter extends BasePresenter<ConfirmRepayContract.Model, ConfirmRepayContract.View> {

    @Inject
    public ConfirmRepayPresenter(ConfirmRepayContract.Model model, ConfirmRepayContract.View rootView) {
        super(model, rootView);
    }


    public void getPreRepaymentInfo(TreeMap<String, Object> map) {

        addSubscribe(mModel.getPreRepaymentInfo(map)
                .compose(RxUtils.<PreRepayment>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<PreRepayment>(mView, true) {
                    @Override
                    public void onNext(PreRepayment data) {
                        mView.onGetPreRepaymentInfo(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.onGetPreRepaymentFailed();
                        super.onError(e);
                    }
                }));
    }


    public void confirmRepay(TreeMap<String, Object> map) {

        addSubscribe(mModel.confirmRepay(map)
                .compose(RxUtils.<String>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<String>(mView, true) {
                    @Override
                    public void onNext(String data) {
                        mView.onConfirmRepaySuccess(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.onGetPreRepaymentFailed();
                        super.onError(e);
                    }
                }));
    }

}




